<?php
namespace app\model;

use think\Model;

class MemberCashlogs extends Model
{

	protected $connection = 'mysql';

	protected $pk = 'id';

	protected $name = 'member_cashlogs';

	public static function upamount($params)
    {
        $uid = $params['uid'];
        $amount = $params['amount'];
        $old_amount = Member::where('id', $uid)->value('balance');
        //更新积分
        if ($amount) {
            self::create([
                'weid' => weid(),
                'uid' => $params['uid'],
                'amount' => $amount,
                'old_amount' => $old_amount,
                'remarks' => $params['remarks'],
                'prefix' => $params['prefix'],
                'create_time' => time(),
                'type' => $params['type'] ?? 1,
            ]);
            if ($params['prefix'] == 1) {
                Member::where('id', $uid)->inc('balance', $amount)->update();
            } else {
                Member::where('id', $uid)->dec('balance', $amount)->update();
            }
        }
    }
	public function member()
    {
        return $this->hasOne(Member::class, 'id', 'uid');
    }
}